package com.arvinclub.web.controller.fun;

import com.arvinclub.service.config.WebSocket;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * 路由/跳转
 */
@Controller
public class RredirectController {
    /**
     * 进入聊天室
     */
    @GetMapping("user/chat.html")
    public String chat() {
        return "chat";
    }

    /**
     * 进入更新日志
     * 即id为4的用户页面
     */
    @GetMapping("user/update.html")
    public String myPage() {
        return "forward:/user/page.html/4";
    }

    /**
     * 获取聊天室人数
     */
    @GetMapping("getCount")
    @ResponseBody
    public String getChatCount() {
        return String.valueOf(WebSocket.getOnlineCount());
    }

    /**
     * 退出登录
     * 清除所有session，并回到登录页面
     */
    @GetMapping("user/exit")
    public String exit(HttpSession httpSession) {
        httpSession.invalidate();
        return "redirect:/";
    }
}
